package com.heima.media.controller;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.heima.common.dto.ResponseResult;
import com.heima.media.dto.NewsAuthDto;
import com.heima.media.dto.WmNewsDto;
import com.heima.media.dto.WmNewsPageDto;
import com.heima.media.entity.WmNews;
import com.heima.media.vo.WmNewsVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import lombok.extern.slf4j.Slf4j;
import org.simpleframework.xml.Path;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.heima.media.service.IWmNewsService;
import java.util.List;
import java.util.Map;

import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 自媒体图文内容信息表 前端控制器
 * </p>
 *
 * @author lj
 * @since 2022-06-28
 */
@Slf4j
@RestController
@RequestMapping("/api/v1/news")
@Api(tags = "自媒体图文内容信息表接口")
@CrossOrigin
public class WmNewsController{

    @Autowired
    private IWmNewsService wmNewsService;

    /**
     * 自媒体图文信息列表查询
     * @param dto
     * @return
     */
    @PostMapping("/list")
    @ApiOperation(value = "自媒体图文信息列表查询", notes = "author:liJie")  // value指名称  notes 备注
    @ApiImplicitParam(name = "dto", value = "查询条件", required = true, dataType = "WmNewsPageDto")
    public ResponseResult listByCondition(@RequestBody WmNewsPageDto dto) {
        log.info("[自媒体微服务======>自媒体图文信息列表查询，接收参数：{}]",dto.toString());
        return wmNewsService.listByCondition(dto);
    }

    /**
     * 根据id查询文章内容
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    @ApiOperation(value = "根据id查询文章内容", notes = "author:liJie")  // value指名称  notes 备注
    @ApiImplicitParam(name = "id", value = "文章id", required = true, dataType = "Integer")
    public ResponseResult getById(@PathVariable("id") Integer id) {
        log.info("[自媒体微服务======>根据id查询文章内容，接收参数：{}]",id);
        WmNews wmNews = wmNewsService.getById(id);
        return ResponseResult.okResult(wmNews);
    }

    /**
     * 保存或修改文章
     * @param dto
     * @return
     */
    @PostMapping("/submit")
    @ApiOperation(value = "保存或修改文章", notes = "author:liJie")  // value指名称  notes 备注
    @ApiImplicitParam(name = "dto", value = "提交文章对象", required = true, dataType = "WmNewsDto")
    public ResponseResult submit(@RequestBody WmNewsDto dto) {
        return wmNewsService.submit(dto);
    }

    /**
     * 自媒体端-文章的上架和下架
     * @param dto
     * @return
     */
    @PutMapping("/down_or_up")
    public ResponseResult downOrUp(@RequestBody WmNewsDto dto){
        return wmNewsService.downOrUp(dto);
    }

    /**
     * 查询文章列表
     * @param dto
     * @return
     */
    @PostMapping("/findPageByName")
    public ResponseResult findPageByName(@RequestBody NewsAuthDto dto){
        return wmNewsService.findPageByName(dto);
    }

    /**
     * 查询文章详情
     * @param id
     * @return
     */
    @GetMapping("/findNewsVoById/{id}")
    public ResponseResult<WmNewsVo> findNewVoById(@PathVariable("id") Integer id){
        return wmNewsService.findNewVoById(id);
    }

    /**
     * 人工审核驳回
     * @param dto
     * @return
     */
    @PostMapping("/auth_fail")
    public ResponseResult authFail(@RequestBody NewsAuthDto dto){
        return wmNewsService.auth(dto,0);
    }

    /**
     * 人工审核通过
     * @param dto
     * @return
     */
    @PostMapping("/auth_pass")
    public ResponseResult authPass(@RequestBody NewsAuthDto dto){
        return wmNewsService.auth(dto,1);
    }







}
